package com.flea.hclv.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.flea.hclv.model.dao.HResourceRelationMapper;
import com.flea.hclv.model.entity.HResourceRelation;
import com.flea.hclv.service.HResourceRelationService;
import com.flea.system.utils.FleaStringUtils;

/**
 * @program: project
 * @description: 资源相关
 * @author: shiliqiang
 * @create: 2018-09-19 19:23
 * @version: 1.0
 */
@Service("hResourceRelationService")
public class HResourceRelationServiceImpl implements HResourceRelationService {

    @Autowired
    private HResourceRelationMapper hResourceRelationMapper;

    @Override
    public void saveImagesRelation(List<HResourceRelation> files, String userId, String uuid) {

        hResourceRelationMapper.deleteByUuid(uuid);

        for (HResourceRelation file : files){
            HResourceRelation entity = new HResourceRelation();
            entity.setId(FleaStringUtils.getGenerateUUID());
            entity.setUuid(uuid);
            entity.setResouceId(file.getResouceId());
            entity.setPath(file.getPath());
            entity.setCreateUser(userId);
            entity.setModifyUser(userId);
            hResourceRelationMapper.insertSelective(entity);
        }
    }
    @Override
	public List<HResourceRelation> findFilePathByUuid(String uuid) {
        return hResourceRelationMapper.selectByUuid(uuid);
	}
    @Override
	public boolean saveImagesRelation(List<HResourceRelation> relations,String userId) {
		
	       for (HResourceRelation file : relations){
	            HResourceRelation entity = new HResourceRelation();
	            entity.setId(FleaStringUtils.getGenerateUUID());
	            entity.setUuid(file.getUuid());
	            entity.setResouceId(file.getResouceId());
	            entity.setPath(file.getPath());
	            entity.setCreateUser(userId);
	            entity.setModifyUser(userId);
	            hResourceRelationMapper.insertSelective(entity);
	        }
		return true;
	}
	@Override
	public boolean deleteByUuids(List<String> uuids) {
		return hResourceRelationMapper.deleteByUuids(uuids)==uuids.size();
	}


}
